<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>


        function Student(name, age, sex) {

            //var this = {};  隐式生成this空对象
            this.name = name;
            this.age = age;
            this.sex = sex;
            this.grade = 2016;

            //return this; 隐式返回this
        }
        var student = new Student('zhangsan', 18, 'male');
        // 不写new关键字，按普通函数进行执行
        // 有了new后，函数执行会发生变化，构造函数内部原理

        //1. 在函数体最前面隐式的加上this = {}
        //2. 执行 this.xxx = xxx;
        //3. 隐式的返回this



        function Person(name, height) {
            this.name = name;
            this.height = height;
            this.say = function() {
                console.log(this.say);
            }
            // return 123; //用了new，返回原始值不管用，但是返回对象管用
                        //可以返回对象捣乱
            // return {};
        }
        console.log(new Person('xiaowang',180).name);
        // ({name:'123'}).name  //可以这样访问对象的属性
    </script>
</body>
</html>